home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / 1.2 / scripts / line-nova.scm.z / line-nova.scm
Text File  |  2002-07-08  |  3KB  |  88 lines

  1. ;;; line-nova.scm for gimp-1.1 -*-scheme-*-
  2. ;;; Time-stamp: <1998/11/25 13:26:44 narazaki@gimp.org>
  3. ;;; Author Shuji Narazaki <narazaki@gimp.org>
  4. ;;; Version 0.7
  5.  
  6. (define (script-fu-line-nova img drw num-of-lines corn-deg offset variation)
  7.   (let* ((*points* (cons-array (* 3 2) 'double))
  8.      (modulo fmod)            ; in R4RS way
  9.      (pi/2 (/ *pi* 2))
  10.      (pi/4 (/ *pi* 4))
  11.      (pi3/4 (* 3 pi/4))
  12.      (pi5/4 (* 5 pi/4))
  13.      (pi3/2 (* 3 pi/2))
  14.      (pi7/4 (* 7 pi/4))
  15.      (2pi (* 2 *pi*))
  16.      (rad/deg (/ 2pi 360))
  17.      (variation/2 (/ variation 2))
  18.      (drw-width (car (gimp-drawable-width drw)))
  19.      (drw-height (car (gimp-drawable-height drw)))
  20.      (drw-offsets (gimp-drawable-offsets drw))
  21.      (old-selection (if (eq? (car (gimp-selection-is-empty img)) TRUE)
  22.                 #f
  23.                 (car (gimp-selection-save img))))
  24.      (radius (max drw-height drw-width))
  25.      (index 0)
  26.      (dir-deg/line (/ 360 num-of-lines)))
  27.     (define (draw-vector beg-x beg-y direction)
  28.       (define (set-point! index x y)
  29.     (aset *points* (* 2 index) x)
  30.     (aset *points* (+ (* 2 index) 1) y))
  31.       (define (deg->rad rad)
  32.     (* (modulo rad 360) rad/deg))
  33.       (define (set-marginal-point beg-x beg-y direction)
  34.     (let ((dir1 (deg->rad (+ direction corn-deg)))
  35.           (dir2 (deg->rad (- direction corn-deg))))
  36.       (define (aux dir index)
  37.         (set-point! index
  38.             (+ beg-x (* (cos dir) radius))
  39.             (+ beg-y (* (sin dir) radius))))
  40.       (aux dir1 1)
  41.       (aux dir2 2)))
  42.       (let ((dir0 (deg->rad direction))
  43.         (off (+ offset (- (modulo (rand) variation) variation/2))))
  44.     (set-point! 0
  45.             (+ beg-x (* off (cos dir0)))
  46.             (+ beg-y (* off (sin dir0))))
  47.     (set-marginal-point beg-x beg-y direction)
  48.     (gimp-free-select img 6 *points* ADD
  49.               TRUE        ; antialias
  50.               FALSE        ; feather
  51.               0        ; feather radius
  52.               )))
  53.  
  54.     (gimp-undo-push-group-start img)
  55.     (gimp-selection-none img)
  56.     (srand (realtime))
  57.     (while (< index num-of-lines)
  58.       (draw-vector (+ (nth 0 drw-offsets) (/ drw-width 2))
  59.            (+ (nth 1 drw-offsets) (/ drw-height 2))
  60.            (* index dir-deg/line))
  61.       (set! index (+ index 1)))
  62.     (gimp-bucket-fill drw FG-BUCKET-FILL NORMAL 100 0 FALSE 0 0)
  63.     (if old-selection
  64.     (begin
  65.       (gimp-selection-load old-selection)
  66.       ;; (gimp-image-set-active-layer img drw)
  67.       ;; delete extra channel by Sven Neumann <neumanns@uni-duesseldorf.de>
  68.       (gimp-image-remove-channel img old-selection)))
  69.     (gimp-undo-push-group-end img)
  70.     (gimp-displays-flush)))
  71.  
  72. (script-fu-register
  73.  "script-fu-line-nova"
  74.  _"<Image>/Script-Fu/Render/Line Nova..."
  75.  "Line Nova. Draw lines with Foreground color from the center of image to the edges. 1st undo cancels bucket-fill. 2nd undo gets orignal selection."
  76.  "Shuji Narazaki <narazaki@gimp.org>"
  77.  "Shuji Narazaki"
  78.  "1997,1998"
  79.  ""
  80.  SF-IMAGE "Image" 0
  81.  SF-DRAWABLE "Drawable" 0
  82.  SF-ADJUSTMENT _"Number of Lines" '(200 40 1000 1 1 0 1)
  83.  SF-ADJUSTMENT _"Sharpness (degrees)" '(1.0 0.0 10.0 0.1 1 1 1)
  84.  SF-ADJUSTMENT _"Offset Radius" '(100 0 2000 1 1 0 1)
  85.  SF-ADJUSTMENT _"Randomness" '(30 0 2000 1 1 0 1)
  86. )
  87. ;;; line-nova.scm ends here
  88.